package com.mock.controller;

import com.alibaba.fastjson.JSON;
import com.mock.entity.PageInfo;
import com.mock.entity.Person;
import com.mock.service.PersonService;
import com.mock.service.impl.personServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.Array;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet("/getPersonList")
public class PersonListController extends HttpServlet {

    private PersonService personService = new personServiceImpl();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        long index = Long.valueOf(req.getParameter("index"));
        long pageSize = Long.valueOf(req.getParameter("pageSize"));
        PageInfo pageInfo = new PageInfo(index,pageSize);
        try {
            List<Person> personList = personService.getPersonList(pageInfo);
            String respJSON = JSON.toJSONString(personList);
            resp.getWriter().write(respJSON);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

    }
}
